<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <template slot="footer">
      <a-button @click="handleCancel">关闭</a-button>
      <a-button v-if="!disableSubmit" type="primary" @click="handleOk">确定</a-button>
    </template>
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
	<a-row>

<a-col :span="12">
        <a-form-item label="员工编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-search-select-tag :disabled="disableSubmit" v-decorator="['partyId', validatorRules.partyId]" dict="Person,name,partyId,typeId = EMPLOYEE" />
        </a-form-item>
</a-col>
<a-col :span="12">
        <a-form-item label="部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-category-select :disabled="disableSubmit" v-decorator="['departmentId', validatorRules.departmentId]" 
          pcode="{table:'HrDepartment',txt:'name',key:'departmentId',idField:'id',pidField:'parentId',hasChildField:'hasChild', condition:' parentId = 0'}" 
          placeholder="请选择部门" back="name" @change="handleCategoryChange"/>
        </a-form-item>
</a-col>
<a-col :span="12">
        <a-form-item label="职位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-search-select-tag :disabled="disableSubmit" v-decorator="['jobId', validatorRules.jobId]" dict="DataDictionary,description,dictionaryCode, dictionaryTypeId =POSITION" />
        </a-form-item>
</a-col>
<a-col :span="12">
        <a-form-item label="转正日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择转正日期" :disabled="disableSubmit" v-decorator="['becomeDate',validatorRules.becomeDate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
</a-col>
<a-col :span="12">
        <a-form-item label="转正原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea :disabled="disableSubmit" v-decorator="['description',validatorRules.description]" rows="4" placeholder="请输入转正原因"/>
         <!-- <a-input v-decorator="['description',validatorRules.description]" :disabled="disableSubmit" placeholder="请输入转正原因"></a-input> -->
        </a-form-item>
</a-col>
<!-- <a-col :span="12">
        <a-form-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择创建时间" :disabled="disableSubmit" v-decorator="['createDate']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
</a-col>
<a-col :span="12">
        <a-form-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['createBy']" :disabled="disableSubmit" placeholder="请输入创建人"></a-input>
        </a-form-item>
</a-col>
<a-col :span="12">
        <a-form-item label="是否转正" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag :disabled="disableSubmit" type="list" v-decorator="['isBecome', validatorRules.isBecome]"
          :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =BOOL_DEFINE" 
          placeholder="请选择"/>
        </a-form-item>
</a-col> -->
<a-col :span="12">
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea :disabled="disableSubmit" v-decorator="['remark']" rows="4" placeholder="请输入备注"/>
          <!-- <a-input :disabled="disableSubmit" v-decorator="['remark']" placeholder="请输入备注"></a-input> -->
        </a-form-item>
</a-col>

 </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
  import JCategorySelect from '@/components/jeecg/JCategorySelect'

  export default {
    name: "HrBecomeFullMemberModal",
    components: { 
      JDate,
      JDictSelectTag,
      JSearchSelectTag,
      JCategorySelect,
    },
    data () {
      return {
        disableSubmit: false,
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          partyId: {
            rules: [
              { required: true, message: '请输入员工编号!'},
            ]
          },
          departmentId: {
            rules: [
              { required: true, message: '请输入部门!'},
            ]
          },
          jobId: {
            rules: [
              { required: true, message: '请输入职位!'},
            ]
          },
          becomeDate:{
            rules: [
              { required: true, message: '请选择转正日期!'},
            ]
          },
          description:{
            rules: [
              { required: true, message: '转正原因!'},
            ]
          },
          isBecome: {
            rules: [
              { required: true, message: '请输入是否转正!'},
            ]
          },
        },
        url: {
          add: "/online/api/createHrBecomeFullMember",
          edit: "/online/api/updateHrBecomeFullMember",
          get: "/online/api/getHrBecomeFullMember",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
		this.visible = true;
		this.model = {};
        if(record.id){
	      httpAction(this.url.get,{id:record.id},"post").then((res)=>{
	         if(res.success){
		        this.model = Object.assign({}, res.result);
		        this.$nextTick(() => {
		           this.form.setFieldsValue(pick(this.model,'partyId','departmentId','jobId','becomeDate','description','createDate','createBy','statusId','isBecome','remark'))
		        })   
	         }
	      })
        }
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
              this.model.statusId = "0"
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success('提交成功!');
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'partyId','departmentId','jobId','becomeDate','description','createDate','createBy','statusId','isBecome','remark'))
      },
      handleCategoryChange(value,backObj){
        this.form.setFieldsValue(backObj)
      }
      
    }
  }
</script>
